<template>
  <!-- 任务管理  -->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="产品名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入产品名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
      </el-form-item>
    </el-form>
    <el-row class="mb20 mt2">
      <el-col :span="24">
        <el-button
          type="primary"

          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
    </el-row>
    <el-table :data="noticeList" :header-cell-style="{ background: '#F3F5FC' }" height="74%">
      <el-table-column label="序号"  align="center" width="100">
        <template slot-scope="scop">
          {{ scop.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        label="任务名称"
        
        prop="taskName"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="接入数据源"  prop="sourceName"/>
      <el-table-column label="输出数据源" prop="storeSourceNameList">
        <template slot-scope="scope">
          <span class="box" v-for="item in scope.row.storeSourceNameList">{{ item }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务状态"  prop="configStatus">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.configStatus"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
                   @click="handleUpdate(scope.row)"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
                @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <editDialog ref="editRef" :title="title" :formData="formData"/>
  </div>
</template>

<script>
import taskListData from './mockData/taskListData.json'
import editDialog from '@/components/accessProduct/taskList/emitDialog.vue'

export default {
  name: 'taskList',
  components: { editDialog },
  data() {
    return {
      title: '',
      noticeList: [],
      queryParams: {
        name: '',
        pageNum: 0,
        pageSize: 20
      },
      formData: {},
      total: 0
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      this.total = taskListData.page.totalCount
      this.noticeList = taskListData.page.list
    },
    // 新增
    handleAdd() {
      this.$refs.editRef.isOpen = true
      this.$refs.editRef.active = 0
      this.title = '添加'

    },
    // 查询
    handleQuery() {

    },
    // 编辑
    handleUpdate() {
      this.$refs.editRef.isOpen = true
      this.$refs.editRef.active = 0
      this.title = '编辑'
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const name = row.taskName
      this.$modal.confirm('是否确认删除"' + name + '"的数据项？').then(function() {
        return true
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.box {
  padding: 2px 5px;
  margin-right: 5px;
  background: #E6EDF9;
  color: rgba(0, 0, 0, .85);
  border-radius: 4px;
}
</style>
